package com.spider.controller;

import com.spider.annotation.mySystemlog;
import com.spider.domain.Article;
import com.spider.domain.ResponseResult;
import com.spider.dto.AddArticleDto;
import com.spider.service.ArticleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 罗振军
 * @version V1.0
 * @Package com.spider.controller
 * @date 2024/7/17 18:25
 */

@RestController
@RequestMapping("/article")
@Api(tags = "文章相关接口文档", description = "我是描述信息")
public class ArticleController {

    @Autowired
    //注入公共模块的ArticleService接口
    private ArticleService articleService;

    //----------------------------------测试mybatisPlus---------------------------------
    @GetMapping("/list")
    //Article是公共模块的实体类
    public List<Article> test() {
        //查询数据库的所有数据
        return articleService.list();
    }

    //----------------------------------测试统一响应格式---------------------------------
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList() {
        //查询热门文章，封装成ResponseResult返回
        ResponseResult result = articleService.hotArticleList();
        return result;
    }

    //----------------------------------分页查询文章的列表---------------------------------
    @GetMapping("/articleList")
    @mySystemlog(xxbusinessName = "分页查询文章的列表")//接口描述，用于'日志记录'功能
    public ResponseResult articleList(Integer pageNum, Integer pageSize, Long categoryId) {
        return articleService.articleList(pageNum, pageSize, categoryId);
    }

    //------------------------------------查询文章详情------------------------------------

    @GetMapping("/{id}") //路径参数形式的HTTP请求，注意下面那行只有加@PathVariable注解才能接收路径参数形式的HTTP请求
    @mySystemlog(xxbusinessName = "根据id查询文章详情")//接口描述，用于'日志记录'功能
    //ResponseResult是spider-framework工程的domain目录的类
    public ResponseResult getArticleDetail(@PathVariable("id") Long id) {//注解里指定的id跟上一行保持一致

        //根据id查询文章详情
        return articleService.getArticleDetail(id);
    }

    //------------------------------------根据文章id从mysql查询文章------------------------------------
    @PutMapping("/updateViewCount/{id}")
    @mySystemlog(xxbusinessName = "根据文章id从mysql查询文章")//接口描述，用于'日志记录'功能
    public ResponseResult updateViewCount(@PathVariable("id") Long id) {
        return articleService.updateViewCount(id);
    }


}
